
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


<script type="text/javascript">
    //$.noConflict();

    $(window).resize(function() {
        $('#grid_pump_gate').datagrid('resize');
    });

    function clearpumpgateFrom(){
        $('#pumpgateForm').form('clear');
    }
	
	function clear_img(){
		$('#gate_img_img').attr('src', '__PUBLIC__/img/no_pic.jpg');
	}

    function clearQueryParamZone(){
        $('#queryForm_pumpgate').form('clear');
    }

    $(function(){
        $('#ps_id_combox').combobox({
            url:'/Manage/AdminCsdt/get_all_combox',
            valueField:'id',
            textField:'name',
            onChange: function (newValue, oldValue) {
                $('#scrmach_id').combobox('reload','/Manage/AdminCsdtMachine/get_all_machine?ps_id='+newValue);
            }
        });
        $('#ps_id_combox_1').combobox({
            url:'/Manage/AdminCsdt/get_all_combox',
            valueField:'id',
            textField:'name',
            onChange: function (newValue, oldValue) {
                $('#scrmach_id_1').combobox('reload','/Manage/AdminCsdtMachine/get_all_machine?ps_id='+newValue);
            }
        });
        $('#grid_pump_gate').datagrid({
            //title:'闸门',
            width: '100%',
            //height: 400,
            fit: true,
            nowrap: false,
            striped: true,
            collapsible:false,
            url:'/Manage/AdminCsdtGate/get_all',
            queryParams:{page:1,rows:20},
            method:'get',
            pageNumber:1,
            pageSize:20,
            idField:'id',
            sortName: 'id',
            sortOrder: 'desc',
            remoteSort: false,
            columns:[[
                {field:'id',title:'序号',width:60,checkbox:true},
                {field:'sta_name',title:'泵站名称',width:180,align:'center'},
                {field:'scrmach_id',title:'格栅机',width:100,align:'center'},
                {field:'gate_id',title:'闸门编码',width:100,align:'center'},
                {field:'gate_name',title:'闸门名称',width:80,align:'center'},
                {field:'gate_typ',title:'闸门类型',width:80,align:'center'},
                {field:'gate_mfr',title:'生产厂家',width:80,align:'center'},
                {field:'gate_model',title:'闸门型号',width:120,align:'center'},
                {field:'gate_motor_power',title:'电机功率(千瓦)',width:120,align:'center'},
                {field:'gata_elev',title:'闸门高程(米)',width:120,align:'center'},
                {field:'gate_h',title:'闸门净高(米)',width:120,align:'center'},
                {field:'gate_wid',title:'闸门净宽(米)',width:120,align:'center'},
                {field:'gate_cntl_typ',title:'闸门控制类型',width:100,align:'center'},
                {field:'gate_swit_sty',title:'闸门启闭型式',width:100,align:'center'},
                {field:'gate_row_num',title:'闸门排数',width:100,align:'center'},
                {field:'gate_hole_num',title:'闸门孔数',width:100,align:'center'},
                {field:'gate_svc_dt',title:'投运日期',width:100,align:'center'},
            ]],
            pagination:true,
            rownumbers:true,
            singleSelect:true,
            toolbar: '#grid_pump_gate_ToolBar',
            onDblClickRow: function(rowIndex, rowData) {
                var selected = $('#grid_pump_gate').datagrid('getSelected');
                if($('#single').is(":hidden")){
                    edit_pumpgate(rowData.id);
                }else{
                    var rows = $('#grid_pump_gate').datagrid('getSelections');
                    if(selected){
                        if(selected.id == rowData.id){
                            edit_pumpgate(rowData.id);
                        }else{
                            $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                        }
                    }else{
                        edit_pumpgate(rowData.id);
                    }
                }
            },
            onLoadSuccess: function(data) {
                $(this).datagrid('resize');
                $('.pump_select').combobox('reload','/Manage/AdminPumpPump/get_all_pump?ps_id='+$('#pumpstation_id').val());
            }
        });

        $('#btnAdd_pumpgate').click(function() {
			clear_img();
            clearpumpgateFrom();
            $("#saveflag_pumpgate").val("add");
            $('#ps_id_combox_1').combobox({
                url:'/Manage/AdminCsdt/get_all_combox',
                valueField:'id',
                textField:'name',
            });
            $('#pumpgate_Dlg').dialog({title:'录入闸门信息',modal:true});
            $('#pumpgate_Dlg').dialog("open");
        });
        $('#btnedit_pumpgate').click(function() {
            var selected = $('#grid_pump_gate').datagrid('getSelected');
            if($('#single').is(":hidden")){
                if (selected) {
                    edit_pumpgate(selected.id);
                }
            }else{
                var rows = $('#grid_pump_gate').datagrid('getSelections');
                if(rows.length == 1 || rows.length == 0){
                    if (selected) {
                        edit_pumpgate(selected.id);
                    }
                    else{
                        $.messager.show({title: "提示",msg: "请选中一条信息，再进行编辑!"});
                    }
                }else{
                    $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                    singleToggle();
                }
            }
        });
        $('#btnDel_pumpgate').click(function() {
            var ids = [];
            var rows = $('#grid_pump_gate').datagrid('getSelections');
            for ( var i = 0; i < rows.length; i++) {
                ids.push(rows[i].id);
            }
            if ((ids != null) && (ids.length > 0)) {
                $.messager.confirm('请确认', '你确定要删除吗？', function(r) {
                    if (r) {
                        $('#batchDelForm_pumpgate').ajaxSubmit({
                            url:"/Manage/AdminCsdtGate/deleteArray",
                            data:{'ids':ids.join(',')},
                            dataType:'json',
                            success: function(data) {
                                console.log(data);
                                if (data.status==1) {
                                    $('#grid_pump_gate').datagrid('reload');
                                    $('#grid_pump_gate').datagrid("unselectAll");
                                    $.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
                                }
                                else $.messager.alert('提示','删除失败！','error');
                            }
                        });

                    }
                });
            }
        });
        $('#btnSearch_pumpgate').click(function() {
            $('#queryParamZone_pumpgate').toggle();
            if($('#queryParamZone_pumpgate').is(":hidden")){
                clearQueryParamZone();
            }
            $('#grid_pump_gate').datagrid("resize");
        });

        $('#btnQuery_pumpgate').click(function() {
            var obj = $('#queryForm_pumpgate').serializeJson();
            $('#grid_pump_gate').datagrid('load',obj);
        });
        var model = 'PumpGate';
        table_index_change(model, 'base');
        $('#queryParamZone_pumpgate').hide();
        $('#single').hide();

        /* WdatePicker({el:'pump_mdate',readOnly:true});
         $dp.hide(); */
    });

    function edit_pumpgate(id) {
        if(id!=""){
            $("#saveflag_pumpgate").val("update");
        }else{
            clearpumpgateFrom();
            $("#saveflag_pumpgate").val("add");
            return;
        }
		clear_img();
        $.ajax({url:"/Manage/AdminCsdtGate/get_obj_json",data:{id:id},dataType:"json",success:function(json, textStatus){
            $('#scrmach_id_1').combobox('reload','/Manage/AdminCsdtMachine/get_all_machine?ps_id='+json.ps_id);
            $('#pumpgateForm').form('load',{
                "id": json.id,
                'ps_id':json.ps_id,
                "scrmach_id": json.scrmach_id,
                "gate_id": json.gate_id,
                "gate_name": json.gate_name,
                "gate_typ": json.gate_typ,
                "gate_mfr": json.gate_mfr,
                "gate_model": json.gate_model,
                "gate_motor_power": json.gate_motor_power,
                "gata_elev": json.gata_elev,
                "gate_h": json.gate_h,
                "gate_wid": json.gate_wid,
                "gate_cntl_typ": json.gate_cntl_typ,
                "gate_swit_sty": json.gate_swit_sty,
                "gate_row_num": json.gate_row_num,
                "gate_hole_num": json.gate_hole_num,
                "gate_svc_dt": json.gate_svc_dt,
                "gate_img": json.gate_img,
            });
            if(json.gate_img!=''){
                $('#gate_img_img').attr('src', json.gate_img);
            }
            $('#pumpgate_Dlg').dialog({title:'编辑闸门信息',modal:true});
            $('#pumpgate_Dlg').dialog("open");
            setFormFocus('#pumpgateForm');
        },error:function(XMLHttpRequest, textStatus, errorThrown) {
            relogin(XMLHttpRequest, textStatus, errorThrown);
        }});
    }

    function submitpumpgateForm() {
        if ($('#pumpgateForm').form('validate')) {
            var submitflag = $("#saveflag_pumpgate").val();
            var url = "";
            console.log(submitflag);
            if (submitflag === "add")
                url = "/Manage/AdminCsdtGate/add";
            if (submitflag === "update")
                url = "/Manage/AdminCsdtGate/edit";
            $('#pumpgateForm').ajaxSubmit({
                url:url,
                dataType:'json',
                success: function(data) {
                    if (data.status==1) {
                        if (submitflag === "add") $('#grid_pump_gate').datagrid('load');
                        if (submitflag === "update") $('#grid_pump_gate').datagrid('reload');
                        $('#pumpgate_Dlg').dialog("close");
                        $.messager.show({title:'提示',msg:'保存成功！',showType:'slide'});
                    }
                    else $.messager.alert('提示','操作失败！\n原因：'+data.msg,'error');
                }
            });
        }
    }
</script>
<table id="grid_pump_gate"></table>
<div id="grid_pump_gate_ToolBar" style="padding:5px;height:auto">
    <div style="margin-bottom:5px">
        <a id="btnAdd_pumpgate" href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true">增加</a>
        <a id="btnedit_pumpgate" href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
        <a id="btnDel_pumpgate" href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
        <a id="btnSearch_pumpgate" href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
        <a id="btnReload" href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="$('#grid_pump_gate').datagrid({url:'/Manage/AdminCsdtGate/get_all',queryParams:{page:1,rows:20}})">重载</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-import" plain="true" onclick="open_dialog('/Manage/Admin/open_window_import?url=/Manage/AdminCsdtGate/import')">导入</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-rescueLog" plain="true" onclick="open_tab('/Manage/AdminCsdtGate/export')">导出</a>
    </div>
    <div id="queryParamZone_pumpgate">
        <form id="queryForm_pumpgate" method="post" action="">
            <table>
                <tr>
                    <td>泵站</td>
                    <td><input id="ps_id_combox" name="ps_id"></td>
                    <td>格栅机</td>
                    <td><select class="easyui-combobox" name="scrmach_id" id="scrmach_id" valueField="id" textField="scrmach_name" data-options="prompt:'{:LANG('pls_input')}'" style="width: 100px;"></select></td>
                    <td>属性</td>
                    <td id="table_field">
                        <input class="easyui-combobox"/>
                    </td>
                    <td>查询条件</td>
                    <td id="condition_td">
                        <input type="text"/>
                    </td>
                    <td><a id="btnQuery_pumpgate" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
                    <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#queryForm_pumpgate').form('clear');">重置</a></td>
                </tr>
            </table>
        </form>
    </div>
</div>
<div id="pumpgate_Dlg" class="easyui-dialog" title="" style="width:700px;height:450px;padding:10px" buttons="#dlg_buttons_pumpgate" closed="true" resizable="true">
    <form id="pumpgateForm" method="post" action="">
        <input id="saveflag_pumpgate" name="saveflag_pumpgate" type="hidden" value="add"/>
        <input type="hidden" name="id" />
        <table border="0">
            <tr>
                <td align="right">泵站</td>
                <td><input id="ps_id_combox_1" required="true" name="ps_id" style="width: 150px;"></td>
                <td  align="right">格栅机：</td>
                <td>
                    <select class="easyui-combobox" name="scrmach_id" id="scrmach_id_1" valueField="id" textField="scrmach_name" data-options="prompt:'{:LANG('pls_input')}',required:true" style="width: 140px;">
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">闸门编码：</td>
                <td>
                    <input class="easyui-validatebox" validType="maxLength[30]" type="text" name="gate_id" required="true"></input>
                </td>
                <td align="right">闸门名称：</td>
                <td>
                    <input class="easyui-validatebox" validType="maxLength[30]" type="text" name="gate_name" required="true"></input>
                </td>
            </tr>
            <tr>
                <td align="right">闸门类型：</td>
                <td>
                    <select class="easyui-combobox" name="gate_typ" data-options="prompt:'{:LANG('pls_input')}'" style="width: 140px;">
                        {:gate_typ()}
                    </select>
                </td>
                <td align="right">生产厂家：</td>
                <td>
                    <input class="easyui-validatebox" type="text" name="gate_mfr"></input>
                </td>
            </tr>
            <tr>
                <td align="right">闸门型号：</td>
                <td>
                    <input class="easyui-validatebox" type="text" name="gate_model"></input>
                </td>
                <td align="right">电机功率（千瓦）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="gate_motor_power" precision="4" style="width: 150px;"></input>
                </td>
            </tr>
            <tr>

                <td align="right">闸门高程（米）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="gata_elev" precision="3" style="width: 150px;"></input>
                </td>
                <td align="right">闸门净高（米）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="gate_h" precision="3" style="width: 150px;"></input>
                </td>
            </tr>
            <tr>
                <td align="right">闸门净宽（米）：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="gate_wid" precision="3" style="width: 150px;"></input>
                </td>
                <td align="right">闸门控制类型：</td>
                <td>
                    <select class="easyui-combobox" name="gate_cntl_typ" data-options="prompt:'{:LANG('pls_input')}'" style="width: 140px;">
                        {:gate_cont_type_option()}
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">闸门启闭型式：</td>
                <td>
                    <select class="easyui-combobox" name="gate_swit_sty" data-options="prompt:'{:LANG('pls_input')}'" style="width: 140px;">
                        {:gate_swit_sty_option()}
                    </select>
                </td>
                <td align="right">闸门排数
                    ：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="gate_row_num" style="width: 150px;"></input>
                </td>
            </tr>
            <tr>
                <td align="right">闸门孔数：</td>
                <td>
                    <input class="easyui-numberbox" type="text" name="gate_hole_num" style="width: 150px;"></input>
                </td>
                <td align="right">投运日期：</td>
                <td>
                    <input type="text" class=" easyui-datebox" name="gate_svc_dt" style="width:140px">
                </td>
            </tr>
            <tr>
                <td>
                    <input id="gate_img_button" type="file" multiple="true" value="" />
                </td>
                <td colspan="3">
                    <input type="hidden" id="gate_img" name="gate_img"/>
                    <img src="__PUBLIC__/img/no_pic.jpg" id="gate_img_img" width="100" height="200">
                    <script>
                        $('#gate_img_button').uploadify({
                            'swf'      : '/Public/uploadfy/uploadify.swf',
                            'uploader' : '/Manage/Admin/uploadify',
                            'buttonText' : '上传闸门图',
                            'onUploadSuccess' : function(file, data, response) {
                                $('#gate_img_img').attr('src', data);
                                $('#gate_img').val(data);
                            }
                        });
                    </script>
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="dlg_buttons_pumpgate" style="text-align: center;">
    <a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="javascript:submitpumpgateForm();">保存</a>
</div>
<form id="batchDelForm_pumpgate" method="post">
</form>